package com.canbot.u05.activity.presidemode.newcode.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.canbot.u05.R;
import com.canbot.u05.activity.presidemode.newcode.bean.HostItemBean;
import com.canbot.u05.activity.presidemode.newcode.interfaces.IItemClick;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class NExeStepAdapter extends RecyclerView.Adapter<NExeStepAdapter.ExeStepViewHolder> {
    private final Context mContext;

    private List<HostItemBean> mTaskList;
    private LayoutInflater layoutInflater;
    private IItemClick mIItemClick;

    private int exePos = -1;

    public void setExePos(int exePos) {
        this.exePos = exePos;
    }

    public NExeStepAdapter(List<HostItemBean> taskList, Context context, IItemClick iItemClick) {
        this.mTaskList = taskList;
        if (mTaskList == null) {
            mTaskList = new ArrayList<>();
        }
        this.mContext = context;
        layoutInflater = LayoutInflater.from(mContext);
        this.mIItemClick = iItemClick;
    }

    @NonNull
    @Override
    public ExeStepViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View views = layoutInflater.inflate(R.layout.host_exe_step, viewGroup, false);
        return new ExeStepViewHolder(views);
    }

    @Override
    public void onBindViewHolder(@NonNull ExeStepViewHolder hostTaskListViewHolder, final int i) {
        hostTaskListViewHolder.btnStep.setText(String.valueOf(i + 1));
        hostTaskListViewHolder.btnStep.setSelected(i == exePos);
        hostTaskListViewHolder.btnStep.setOnClickListener(v -> {
            if (mIItemClick != null) {
                mIItemClick.onClick(i, v);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mTaskList.size();
    }

    public class ExeStepViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.btn_step)
        TextView btnStep;

        public ExeStepViewHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
